movieClip in Array displays null, and aren't showing up on stage.addChild(Array[i])

Posted by jtdino on Stack Overflow See other posts from Stack Overflow or by jtdino
Published on 2010-04-26T17:50:45Z Indexed on 2010/04/26 17:53 UTC
Read the original article Hit count: 284

i am new to Actionscript3, i need to know why i keep getting Parameter child must be non-null. And my code won't display 5 enemyBlock objects onto the stage but only just one. any tips and help will be much appreciated. thanks in advance.

returns: TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChild() at flash.display::Stage/addChild() at BlockDrop_fla::MainTimeline/EnemyBlockPos() at BlockDrop_fla::MainTimeline/frame2()

// declare varibles 
var isEnemyMoving:Boolean = false; 
var enemyArray:Array; 
var enemyBlock:MovieClip = new EnemyBlock(); // assign EnemyBlock class to enemyBlock
var enemyBlockMC:MovieClip; 

var count:int = 5;

var mapWidth:Number = 800;
var mapHeight:Number = 600;

function EnemyBlockPos() :void {

    // assign new MovieClip not null
    enemyBlockMC = new MovieClip;
    enemyArray = new Array();

        for(var i=1; i<= count; i++){ 
            // add class to MC
            enemyBlockMC.addChild(enemyBlock);
            // randomize position
            enemyBlock.x = Math.round(Math.random()*mapWidth);
            enemyBlock.y = Math.round(Math.random()*mapHeight);
            // set motion
            enemyBlock.movement = 5;

            // add MC to array
            enemyArray.push(enemyBlockMC);
        }


        for (var w = 1; w <= enemyArray.length; w++) {
                addChild(enemyArray[w]);
            }

} // endOf EnemyBlockPos

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash-cs4